{extend name='public/base' /}

{block name="content"}

<div class="layui-col-md12">
    <div class="layui-card">
        <div class="layui-card-body">
            <form action="" class="layui-form" method="get">
                <div class="layui-form-item layui-form-pane">
                    <div class="layui-inline">
                        <label class="layui-form-label">商户：</label>
                        <div class="layui-input-inline">
                            <select name="merchant_id" lay-verify="required" lay-search="">
                                <option value="0" ></option>
                                {volist name="merchant_list" id="t"}
                                {if empty($t.name)||$t.name=='-'}
                                <option value="{$t.id}" >{$t.company} - {$t.code}-{$t.biz_state}-{$t.positions_code}</option>
                                {else/}
                                <option value="{$t.id}" >{$t.name} - {$t.code}-{$t.biz_state}-{$t.positions_code}</option>
                                {/if}
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn icon-btn layui-btn-sm" data-id="table_id" lay-filter="search"
                            lay-submit="">
                            <i class="layui-icon"></i>搜索
                        </button>
                        <button type="reset" class="layui-btn icon-btn layui-btn-normal layui-btn-sm"><i
                                class="layui-icon layui-icon-refresh"></i>{:__('Reset')}
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" id="table_id" lay-filter="table_id"></table>
        </div>
    </div>

</div>
{/block}

{block name="js"}
<!--js处理区-->


<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <!-- <button type="button" lay-event="add" class="layui-btn {:node('Cost/add')} layui-btn-sm">去缴费</button> -->
        <button type="button" lay-event="reload" class="layui-btn  layui-btn-sm  layui-btn-primary">刷新表格</button>
    </div>
</script>

<script type="text/html" id="operationTpl">
    <a href="javascript:;" class="layui-btn  layui-btn-primary layui-btn-xs {:node('RepairMarrer/detail')}" data-title="查看" lay-event="detail"><i class="layui-icon">&#xe705;</i></a>
</script>

<script>
    layui.use(['element', 'table', 'form', 'jquery', 'lucky', 'opTable'], function () {
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var lucky = layui.lucky;
        var opTable = layui.opTable;
        var isSelect = false;
        form.render();

        var myTables = table.render({
            elem: '#table_id',
            url: "{:url('index')}",
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: ['filter', 'exports', 'print'],
            even: true, //开启隔行背景
            id: 'table_id',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip', 'last'] //自定义分页布局
                , groups: 5 //只显示 1 个连续页码
                , first: false //不显示首页
                , last: false //不显示尾页
                , limit: 20
                , limits: [10, 20, 30, 50]
            },
            // height: 'full-100',100',
            text: {
                none: '暂无相关数据'
            },
            cols: [[
                { title: '', type: 'checkbox', fixed: true },
                {title: '商户编号', field: 'merchant', templet: function (item) {
                        return item.merchant.merchant_sn
                    }
                },
                {title: '商户公司', field: 'merchant', templet: function (item) {
                        return item.merchant.company
                    }
                },
                {title: '合同号', field: 'merchant', templet: function (item) {
                        return item.merchant.code
                    }
                },
                // { title: 'ID', field: 'id',width:60},
                { title: '申报人', field: 'applicant', width: 100 },
                { title: '手机号', field: 'mobile', width: 100 },
                {
                    title: '报事类型', field: 'type', templet: function (item) {
                        return item.title
                    }
                },
                {
                    title: '申报内容', field: 'content'
                },
                {
                    title: '申报编号', field: 'order_sn'
                },
                {
                    field: 'create_time', title: '创建时间', width: 160, templet: function (item) {
                        return layui.util.toDateString((item.create_time) * 1000)
                    }
                },
                {
                    field: 'start_time', title: '开始时间', width: 120, templet: function (item) {
                        return layui.util.toDateString((item.start_time) * 1000,'yyyy-MM-dd')
                    }
                },
                {
                    field: 'end_time', title: '结束时间', width: 120, templet: function (item) {
                        return layui.util.toDateString((item.end_time) * 1000,'yyyy-MM-dd')
                    }
                },
                {
                    field: 'status', title: '状态', width: 120, templet: function (item) {
                        if (item.status == 1) {
                            return '待审核';
                        } else if (item.status == 2) {
                            return '审核通过';
                        } else if (item.status == 3) {
                            return '审核拒绝';
                        } else{
                            return ''
                        }
                    }
                },
                { templet: '#operationTpl', align: 'center', minWidth: 160, title: '操作' }
            ]],
            //  展开的列配置
            openCols: [
                { field: 'desc', title: '描述信息' }
            ],
            done: function (res) {
                layer.closeAll('loading');
            }
        });


        /**
         * 监听单行工具操作
         */
        table.on('tool(table_id)', function (obj) {
            var data = obj.data;
            var _id = parseInt(data.id);
            var layEvent = obj.event;
            if (layEvent === "detail") {
                lucky.CreateOpenForm("查看", "{:url('detail')}?id=" + _id);
                return false;
            }
        });

        table.on('toolbar(table_id)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            if (obj.event === "add") {
                if (isSelect == false) {
                    layer.msg("请先搜索", { time: 1500 });
                    return false;
                }
                var num = 0;
                var id = [];
                for (var i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num < 1) {
                    layer.msg("请选择一项", { time: 1500 });
                    return false;
                }
                lucky.CreateOpenForm("商户后台缴费", "{:url('add')}?id=" + id);
                // lucky.CreateOpenForm("缴费详情","{:url('detail')}?id=" + _id);
                return false;
            } else if (obj.event === "cui") {
                var num = 0;
                var id = [];
                for (var i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num < 1) {
                    layer.msg("请选择一项", { time: 1500 });
                    return false;
                }
                console.log(id);
                lucky.CreateOpenForm("催费", "{:url('rushFee')}?id= " + id);
                return false;
            }

        });

        /**
         * 关键词搜索树
         */
        form.on('submit(search)', function (obj) {
            isSelect = true;
            lucky.CreateSearch(obj.field);
            return false;
        });
    });

</script>

{/block}